<!DOCTYPE html>
<html>

	<head lang="en">
		<title>找攻略</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap/js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="/css/reset.css" />
		<link rel="stylesheet" href="/css/strategy.css" />
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
		<script src="/js/plugins/dialog2/dialog.min.js"></script>
		<script>
            $(function () {
                //获取推荐的游记
				$.get("/travelCommend",{type:3},function (data) {
					$("#commendTravel").renderValues({list:data.list},{
					    setHref:function (item, value) {
					        //重新设置href
							$(item).attr("href",$(item).attr("href")+value)
                        }
					})
                    $(".carousel-item:first").addClass("active");
                })
				//获取推荐的攻略,禁用分页
                $.get("/strategies",{state:2,pageSize:0},function (data) {
                    $("#hotStrategy").renderValues({list:data.list},{
                        setHref:function (item, value) {
                            //重新设置href
                            $(item).attr("href",$(item).attr("href")+value)
                        }
                    })
                })




			//拼接页签
                var html="";
                var commends="";
                $.get("/regions/1",function (data) {
                    //因为传过来的是一堆地区对象,是一个list
                    $.each(data,function (index,ele) {

                        html+='<li class="nav-item"><a data-id="'+ele.id+'" class="nav-link" id="pills-'+ele.id+'-tab" data-toggle="pill" href="#pills-'+ele.id+'">'+ele.name+'</a></li>'
                        commends+='<div class="tab-pane fade" id="pills-'+ele.id+'"></div>'
                    })
                    $("#pills-tab").append(html)
                    $("#pills-tabContent").append(commends)
                })
				//先定义一个变量接收placeId,滑动分页的时候需要使用
                var currentPage;
				var totalPage;
				var placeId;
				$("#pills-tab").on("click",".nav-link",function () {
                    placeId=$(this).data("id");
                    console.log("2:"+placeId);
                    $.get("/regions/" + placeId + "/strategies", function (data) {
						$("#pills-"+placeId).html(data);
                    },"html")

                    currentPage=2;
                    totalPage=2;
                })
                $(window).scroll(function () {
                    if ($(window).height() + $(window).scrollTop() >= $(document).height()) {
                        if (currentPage <= totalPage) {
                            console.log(currentPage);
                            $.get("/regions/" + placeId + "/strategies", {currentPage:currentPage},function (data) {
                                //合并数组,返回第一个数据,如[1,2]和[3]编程[1,2,3]
                                //数据渲染
                                console.log(data);
                                var htmls="";
								$.each(data.list,function (index, ele) {

                                    htmls+='<div class="col-6 mb">'+
                                        '<a href="/strategyCatalogs.html?strategyId='+ele.id+'">'+
                                        '<img class="float-left " src="'+ele.coverUrl+'"/>'+
                                        '<div class="classify-text">'+
                                        '<span>'+ele.title+'</span>'+
                                        '<p>1999人收藏</p>'+
										'</div>'+
										'</a>'+
										'</div>'
                                })
                                totalPage=data.pages;
                                currentPage += 1;
                                $("#classifyStrategies").append(htmls)
                            },"json")
                        } else {
                            $(document).dialog({
                                type: 'toast',
                                content: '<span class="info-text">到底了</span>',
                                autoClose: 2500
                            });
                        }
                    }
                })

				//搜索
				$(".searchBtn").change(function () {

                    var keyword = $("#searchBtn").val();
                    sessionStorage.setItem("keyword",keyword);
                    window.location.href = "/searchPage.html";
                })

            })
		</script>
	</head>

	<body>
	<div class="search-head">
		<div class="row nav-search">
			<div class="col-2">
				<a href="/index.html">
					<span><i class="fa fa-chevron-left fa-2x"></i></span>
				</a>
			</div>
			<div class="col-10">
				<div class="input-group-sm search">
					<input id="searchBtn" class="form-control searchBtn" placeholder="找攻略">
				</div>
			</div>
		</div>
	</div>

	<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab" role="tablist">
		<li class="nav-item">
			<a class="nav-link active show" id="pills-top-tab" data-toggle="pill" href="#pills-top">
				<span style="font-weight: bold;">推荐</span>
			</a>
		</li>

	</ul>
	<div class="tab-content" id="pills-tabContent">
		<div class="tab-pane fade active show" id="pills-top">
			<div id="commendTravel" class="container">
				<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">

				<div class="container commend carousel-inner" render-loop="list">
					<div class="carousel-item">
						<div class="border commend">
							<a href="travelContent.html?id=" render-fun="setHref" render-key="list.travelId">
								<img render-src="list.travelcommendCoverUrl"  width="100%" height="200px" >
								<p render-html="list.travelcommendTitle"></p>
							</a>
						</div>
					</div>
				</div>

				<a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
					<span class="carousel-control-prev-icon" aria-hidden="true"></span>
					<span class="sr-only"></span>
				</a>
				<a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
					<span class="carousel-control-next-icon" aria-hidden="true"></span>
					<span class="sr-only"></span>
				</a>
				</div>
			</div>
			<hr>
			<div class="container strategyCommend">
				<h6>当季推荐</h6>
				<div id="hotStrategy">
					<div class="row hot" render-loop="list">
						<div class="col-4">
							<a href="strategyCatalogs.html?strategyId=" render-fun="setHref" render-key="list.id">
								<img render-src="list.coverUrl">
								<p render-html="list.title"></p>
							</a>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	</body>

</html>